package com.itboye.ihomebank.adapter.key;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.bean.ICCardListBean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2018/8/7 0007.
 */

public class ItemICCardAdapter extends BaseAdapter {

    private Context context;
    List<ICCardListBean.ICCardBean> mList;
    private LayoutInflater inflater;
    public ItemICCardAdapter(Context context, List<ICCardListBean.ICCardBean> mList){

        this.context=context;
        this.mList=mList;
        inflater=LayoutInflater.from(context);
        Log.d("==========",mList.size()+"");
    }
    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder myViewHolder;
        if (convertView==null){
            myViewHolder=new MyViewHolder();
            convertView = inflater.inflate(R.layout.item_iccard, null, false);
            myViewHolder.time= (TextView) convertView.findViewById(R.id.time);
            myViewHolder.title= (TextView) convertView.findViewById(R.id.title);
            convertView.setTag(myViewHolder);
        }else {
            myViewHolder= (MyViewHolder) convertView.getTag();
        }
            myViewHolder.title.setText(mList.get(position).getCard_name());
            SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd HH:mm");
            if (Long.parseLong(mList.get(position).getEnd())>0){
                String startTimes = format.format(new Date(Long.parseLong(mList.get(position).getStart())*1000));
                String endTimes = format.format(new Date(Long.parseLong(mList.get(position).getEnd())*1000));
                myViewHolder.time.setText(startTimes+"-"+endTimes);
            }else {
               myViewHolder.time.setText("永久");
            }
//            new Date()
//        myViewHolder.time.setText();
//        format.format()
            return convertView;
    }

    public void addData(List<ICCardListBean.ICCardBean> mList){
            this.mList=mList;
            this.notifyDataSetChanged();
    }

    class MyViewHolder{

            TextView title,time;
    }
}
